#include "qadduserdialog.h"
#include "ui_qadduserdialog.h"

#include "../../libs/sharedLib/qnamevalidator.h"

#include "../../libs/sharedlib/qprojectcore.h"
#include "../../libs/sharedlib/qusermanager.h"

QAddUserDialog::QAddUserDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::QAddUserDialog),
    m_userName(new SHAREDLIB::QNameEdit("(.*)",this))
{
    ui->setupUi(this);
    this->setProperty("no-ManhattanStyle",true);
    m_userName->setFocus();

    ui->horizontalLayout->addWidget(m_userName);

    SHAREDLIB::QProjectCore *core=SHAREDLIB::QProjectCore::getCore();
    SHAREDLIB::QUserManager *manager=core->userManager();
    QStringList list;
    for(int i=0;i<manager->userCount();i++)
    {
        list.append(manager->getUser(i)->property("userName").toString());
    }
    m_userName->setIntermediateList(list);
    m_userName->setFocus();
}

QAddUserDialog::~QAddUserDialog()
{
    delete ui;
}

void QAddUserDialog::on_okBtn_clicked()
{
    QString name,password;
    name=m_userName->value();
    password=ui->password->text();
    if(name=="")
    {
        return;
    }
    m_name=name;
    m_password=password;
    m_level=ui->level->value();
    close();
}

void QAddUserDialog::on_cancelBtn_clicked()
{
    close();
}

QString QAddUserDialog::getName()
{
    return m_name;
}

QString QAddUserDialog::getPassword()
{
    return m_password;
}

int QAddUserDialog::getLevel()
{
    return m_level;
}
